package com.itlong.cloud.property;


import com.itlong.cloud.iottp.IIotTpSmsServiceClient;
import com.itlong.cloud.project.property.IPropertyCloudServiceCostMessageServiceClient;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      物业云服务费消息通知定时任务.
 * </desc>
 *
 * @createDate 2018/7/5
 */
@EnableScheduling // 启用定时任务
@RestController
public class PropertyCloudServiceCostPushMessageTimedTask {
    private static Logger LOG = LoggerFactory.getLogger(PropertyCloudServiceCostPushMessageTimedTask.class);

    @Autowired
    IPropertyCloudServiceCostMessageServiceClient iPropertyCloudServiceCostMessageServiceClient;

    @Autowired
    IIotTpSmsServiceClient iIotTpSmsServiceClient;


    @Scheduled(cron = "0 0 6 * * ?") // 每天早上6点执行
    //@Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
    public void timeTaskSychro() throws Exception {

        try {
            List<Map<String,String>> list = iPropertyCloudServiceCostMessageServiceClient.savePushMessage();
            if(null != list){
                for(Map<String,String> map : list){
                    String propertyName = map.get("propertyName");
                    String projectName = map.get("projectName");
                    String endDays = map.get("endDays");
                    String propertyPhone = map.get("propertyPhone");
                    if(StringUtils.isNotEmpty(propertyPhone)){
                        String content = "尊敬的"+propertyName+"：您在"+projectName+"设备云服务费，将在"+endDays+"天后到期，为避免影响正常使用请登录云半径物业管理系统进行续费。";
                        iIotTpSmsServiceClient.sendSmsCodeByPhone(propertyPhone,content);
                    }
                }
            }
//            LOG.info("【定时任务】物业云服务费消息通知定时任务");
        } catch (Exception e) {
            throw e;
        }

    }
}